/*****************************************************************************/
/**
 *  @file   ImportSPHFile.cpp
 *  @author Naohisa Sakamoto
 */
/*----------------------------------------------------------------------------
 *
 *  Copyright (c) Visualization Laboratory, Kyoto University.
 *  All rights reserved.
 *  See http://www.viz.media.kyoto-u.ac.jp/kvs/copyright/ for details.
 *
 *  $Id$
 */
/*****************************************************************************/
#include "ImportSPHFile.h"
#include <kvs/StructuredVolumeObject>
#include <kvs/Vector3>
#include <kvs/AnyValueArray>
#include "SPHFile.h"


namespace kvsbloodvis
{

namespace util
{

/*===========================================================================*/
/**
 *  @brief  Imports SPH file as a structured volume object.
 *  @param  sph [in] SPH file
 *  @return structured volume object
 */
/*===========================================================================*/
kvs::StructuredVolumeObject ImportSPHFile( const SPHFile& sph )
{
    size_t veclen = sph.svType() == 1 ? 1 : 3;
    kvs::Vector3ui resolution = sph.resolution();
    kvs::AnyValueArray values = sph.data();

    kvs::StructuredVolumeObject volume;
    volume.setGridType( kvs::StructuredVolumeObject::Uniform );
    volume.setVeclen( veclen );
    volume.setResolution( resolution );
    volume.setValues( values );
    volume.updateMinMaxCoords();
    volume.updateMinMaxValues();

    return volume;
}

} // end of namespace util

} // end of namespace kvsbloodvis
